import { _decorator, Component, Node, TiledMap, TiledUserNodeData, UITransform } from 'cc';
const { ccclass, property, executeInEditMode } = _decorator;

@ccclass('TileMapAPI')
@executeInEditMode
export class TileMapAPI extends Component {
    start() {
        const tileMap = this.getComponent(TiledMap)
        // console.log("mapSize", tileMap.getMapSize())
        // console.log("tileSize", tileMap.getTileSize())
        // console.log("tmxAsset", tileMap.tmxAsset)
        // console.log("orientation", tileMap.getMapOrientation())
        // console.log('layers', tileMap.getLayers().length)
        // console.log('properties', tileMap.getProperties())
        // console.log('objectGroups', tileMap.getObjectGroups()[0])

        //tmx
        const tsx = tileMap.tmxAsset
        // console.log("tsx", tsx.tmxXmlStr, tsx.tsxFiles, tsx.tsxFileNames)
        // console.log("spriteFrame", tsx.spriteFrameNames)

        //tilelayer
        const layer = tileMap.getLayers()[0]
        console.log('layerName:', layer.name, layer.getLayerName())
        console.log(layer.hasTiledNode(), layer.hasAnimation())

        const newNode = new Node('userNode')
        newNode.addComponent(UITransform)
        layer.addUserNode(newNode)
        // console.log("userNode", newNode.getComponent(TiledUserNodeData))

        // console.log('userNodeName:', layer.getNodesByRowCol(13, 13).list[0].name)

        // console.log('property', layer.getProperties())

        // console.log('getPositionAt', layer.getPositionAt(1, 1))

        // layer.setTileGIDAt(10, 5, 9)
        console.log('flag', layer.getTileFlagsAt(5, 9))

        //tiled-tile
        console.log('layer', layer.tiledTiles)
    }

    update(deltaTime: number) {
        
    }
}


